package thread.threadpool.example3;


import thread.threadpool.example2.MyRunnable;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 测试ScheduleExecutorService接口中的延迟执行任务和重复执行任务的功能
 * @date: 2023/1/31 10:55
 * @author: Huangjunjie
 * @since JDK 1.8
*/
public class ScheduleExecutorServiceDemo01 {
    public static void main(String[] args) {
        //1.获取一个具备延迟执行任务的线程池对象
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(3);
        //2.创建多个任务对象，提交任务，每个任务延迟2秒执行
//        for (int i = 0; i < 10; i++) {
//            pool.schedule(new MyRunnable(i),1, TimeUnit.SECONDS);
//        }
        pool.schedule(new MyRunnable(3),1, TimeUnit.SECONDS);
        System.out.println("执行结束");
    }

}
